package com.cyufeng.blog.controller;

import com.cyufeng.blog.dto.ArticleDto;
import com.cyufeng.blog.dto.MoodDto;
import com.cyufeng.blog.service.MoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 心情
 *
 * @author Cyufeng
 * Data:2018.12.30
 */
@CrossOrigin
@RequestMapping("/blog/mood")
@RestController
public class MoodController {
    @Autowired
    MoodService moodService;

    /**
     * 保存心情
     *
     * @param moodValue 心情的值
     * @return 成功返回success 失败返回 error
     */
    @GetMapping("/saveMood")
    public String saveMood(@RequestParam("moodValue") String moodValue) {
        return moodService.saveMood(moodValue);
    }

    /**
     * 得到所有心情
     *
     * @return List<List < MoodDto>>
     */

    @GetMapping("/getAllMood")
    public List<List<MoodDto>> getAllMood() {
        List<List<MoodDto>> moodDtoList = moodService.getAllMood();
        return moodDtoList;
    }

    /**
     * 分页查询所有心情
     *
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/getMoodPage")
    public Map<String, Object> showSpecPage(@RequestParam(value = "page") Integer page, @RequestParam(value = "size") Integer size) {
        return moodService.getAllMoodPage(page, size);
    }

    /**
     * 分页查询所有心情--用于后台操作
     *
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/getAllMood_Back")
    public Map<String, Object> getAllMood_Back(@RequestParam(value = "page") Integer page, @RequestParam(value = "size") Integer size) {
        return moodService.getAllMood_Back(page, size);
    }

    /**
     * 删除用户
     *
     * @return
     */
    @GetMapping("/deleteMood")
    public String deleteMood(@RequestParam("id") int id) {

        return moodService.deleteMood(id);
    }

    /**
     * 保存修改的心情
     *
     * @param moodDto
     * @return
     */
    @PostMapping("/saveEdit")
    public String saveMoodTest(@RequestBody MoodDto moodDto) {
        String r = moodService.saveEditMood(moodDto);
        return r;
    }

}
